home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 July: Mac OS SDK / Dev.CD Jul 96 SDK / Dev.CD Jul 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc Development Framework / ODFDev / ODF / Framewrk / FWPart / Sources / FWPxyFrm.cpp < prev    next >
Encoding:
Text File  |  1996-04-25  |  21.7 KB  |  704 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWPxyFrm.cpp
  4. //    Release Version:    $ ODF 1 $
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "FWFrameW.hpp"
  11.  
  12. #ifndef FWPXYFRM_H
  13. #include "FWPxyFrm.h"
  14. #endif
  15.  
  16. #ifndef FWPARTNG_H
  17. #include "FWPartng.h"
  18. #endif
  19.  
  20. #ifndef FWFRMING_H
  21. #include "FWFrming.h"
  22. #endif
  23.  
  24. #ifndef FWPROXY_H
  25. #include "FWProxy.h"
  26. #endif
  27.  
  28. #ifndef FWUTIL_H
  29. #include "FWUtil.h"
  30. #endif
  31.  
  32. #ifndef FWCLNINF_H
  33. #include "FWClnInf.h"
  34. #endif
  35.  
  36. // ----- OS Layer -----
  37.  
  38. #ifndef FWBARRAY_H
  39. #include "FWBArray.h"
  40. #endif
  41.  
  42. #ifndef FWGRUTIL_H
  43. #include "FWGrUtil.h"
  44. #endif
  45.  
  46. #ifndef FWODGEOM_H
  47. #include "FWODGeom.h"
  48. #endif
  49.  
  50. // ----- OpenDoc Includes -----
  51.  
  52. #ifndef SOM_ODFrame_xh
  53. #include <Frame.xh>
  54. #endif
  55.  
  56. #ifndef SOM_ODFacet_xh
  57. #include <Facet.xh>
  58. #endif
  59.  
  60. #ifndef SOM_Module_OpenDoc_StdProps_defined
  61. #include <StdProps.xh>
  62. #endif
  63.  
  64. #ifndef SOM_ODStorageUnitView_xh
  65. #include <SUView.xh>
  66. #endif
  67.  
  68. #ifndef SOM_Module_OpenDoc_StdTypes_defined
  69. #include <StdTypes.xh>
  70. #endif
  71.  
  72. #ifndef SOM_ODEmbeddedFramesIterator_xh
  73. #include <EmbFrItr.xh>
  74. #endif
  75.  
  76. #ifndef SOM_ODTransform_xh
  77. #include <Trnsform.xh>
  78. #endif
  79.  
  80. #ifndef SOM_ODDraft_xh
  81. #include <Draft.xh>
  82. #endif
  83.  
  84. #if defined(__MWERKS__) && GENERATING68K
  85. // A hack to work around a bug
  86. #pragma import list somGetGlobalEnvironment
  87. #endif
  88.  
  89. //========================================================================================
  90. //    RunTime Info
  91. //========================================================================================
  92.  
  93. #ifdef FW_BUILD_MAC
  94. #pragma segment fw_embedding2
  95. #endif
  96.  
  97.  
  98. //========================================================================================
  99. //    Template Instantiations
  100. //========================================================================================
  101.  
  102. FW_DEFINE_AUTO_TEMPLATE(FW_TOrderedCollectionIterator, FW_CProxyFrame)
  103. FW_DEFINE_AUTO_TEMPLATE(FW_TOrderedCollection, FW_CProxyFrame)
  104.  
  105. #ifdef FW_USE_TEMPLATE_PRAGMAS
  106.  
  107. #pragma template_access public
  108. #pragma template FW_TOrderedCollection<FW_CProxyFrame>
  109. #pragma template FW_TOrderedCollectionIterator<FW_CProxyFrame>
  110.  
  111. #endif
  112.  
  113. //========================================================================================
  114. //    class FW_CProxyFrame
  115. //========================================================================================
  116.  
  117. //----------------------------------------------------------------------------------------
  118. //    FW_CProxyFrame::FW_CProxyFrame
  119. //----------------------------------------------------------------------------------------
  120.  
  121. FW_CProxyFrame::FW_CProxyFrame(Environment* ev, 
  122.                                 FW_MProxy* proxy,
  123.                                 FW_CEmbeddingPart* part) :
  124.     fPart(part),
  125.     fProxy(proxy),
  126.     fFrameID(kODNULLID),
  127.     fContainingFrameID(kODNULLID),
  128.     fEmbeddedFrame(NULL),
  129.     fPurgeable(FALSE),
  130.     fAttached(TRUE),
  131.     fFrameDraft(NULL)
  132. {
  133. FW_UNUSED(ev);
  134.     FW_ASSERT(fPart != NULL);
  135. }
  136.  
  137. //----------------------------------------------------------------------------------------
  138. //    FW_CProxyFrame::FW_CProxyFrame
  139. //----------------------------------------------------------------------------------------
  140.  
  141. FW_CProxyFrame::FW_CProxyFrame(Environment* ev, 
  142.                                 FW_MProxy* proxy,
  143.                                 FW_CEmbeddingPart* part, 
  144.                                 FW_CEmbeddingFrame* containingFrame, 
  145.                                 ODFrame* embeddedFrame) :
  146.     fPart(part),
  147.     fProxy(proxy),
  148.     fFrameID(kODNULLID),
  149.     fContainingFrameID(kODNULLID),
  150.     fEmbeddedFrame(embeddedFrame),
  151.     fPurgeable(FALSE),
  152.     fAttached(TRUE),
  153.     fFrameDraft(NULL)
  154. {
  155.     FW_ASSERT(fPart != NULL);
  156.     FW_ASSERT(fProxy != NULL);
  157.     FW_ASSERT(containingFrame != NULL);
  158.     FW_ASSERT(fEmbeddedFrame != NULL);
  159.     FW_ASSERT(containingFrame->GetPart(ev) == part);
  160.     
  161.     fEmbeddedFrame->Acquire(ev);
  162.     fFrameID = fEmbeddedFrame->GetID(ev);
  163.  
  164.     // ----- Save embedded frame's draft if persistent frame
  165.     ODStorageUnit* frameSU = fEmbeddedFrame->GetStorageUnit(ev);
  166.     if (frameSU != NULL)
  167.         fFrameDraft = frameSU->GetDraft(ev);
  168.     
  169.     fContainingFrameID = containingFrame->GetID(ev);
  170.  
  171. #ifdef FW_DEBUG
  172.     {
  173.         FW_CAcquiredODFrame aqContainingFrame = embeddedFrame->AcquireContainingFrame(ev);
  174.         FW_ASSERT(aqContainingFrame == containingFrame->GetODFrame(ev));
  175.     }
  176. #endif
  177.  
  178.     // ----- If the frame was in Limbo -----
  179.     embeddedFrame->SetInLimbo(ev, FALSE);
  180. }
  181.  
  182. //----------------------------------------------------------------------------------------
  183. //    FW_CProxyFrame::~FW_CProxyFrame
  184. //----------------------------------------------------------------------------------------
  185.  
  186. FW_CProxyFrame::~FW_CProxyFrame()
  187. {
  188.     // [HLX] Need a try block
  189.     if (fEmbeddedFrame)
  190.     {
  191.         Environment* ev = somGetGlobalEnvironment();
  192.         if (FW_IsInLimbo(ev, fEmbeddedFrame))    // [HLX] do not call ODFrame::IsInLimbo. see FW_IsInLimbo
  193.         {
  194.             // If the embedded frame doesn't have fContainingFrameID as containing frame then 
  195.             // doesn't remove
  196.             FW_CAcquiredODFrame embeddingFrame = fEmbeddedFrame->AcquireContainingFrame(ev);
  197.             if (embeddingFrame == NULL || embeddingFrame->GetID(ev) == fContainingFrameID)
  198.                 fEmbeddedFrame->Remove(ev);
  199.             else
  200.                 fEmbeddedFrame->Release(ev);
  201.         }
  202.         else
  203.             fEmbeddedFrame->Release(ev);
  204.     }
  205. }
  206.  
  207. //----------------------------------------------------------------------------------------
  208. //    FW_CProxyFrame::GetContainingFrame
  209. //----------------------------------------------------------------------------------------
  210. //    GetContainingFrame returns null if the containing frame of this proxyframe is not a valid 
  211. //    display frame
  212.  
  213. FW_CEmbeddingFrame* FW_CProxyFrame::GetContainingFrame(Environment* ev) const
  214. {
  215.     FW_CProxyFrame* self = (FW_CProxyFrame*)this;
  216.     
  217.     if (fPart->IsValidDisplayFrame(ev, fContainingFrameID))
  218.     {
  219.         FW_CAcquiredODFrame aqContainingODFrame =  fPart->GetDraft(ev)->AcquireFrame(ev, fContainingFrameID);
  220.  
  221.         FW_CEmbeddingFrame* containingFrame = FW_CEmbeddingFrame::ODtoFWEmbeddingFrame(ev, aqContainingODFrame);
  222.         FW_ASSERT(containingFrame != NULL);
  223.     
  224.         return containingFrame;
  225.     }
  226.     
  227.     return NULL;
  228. }
  229.  
  230. //----------------------------------------------------------------------------------------
  231. //    FW_CProxyFrame::GetFrame
  232. //----------------------------------------------------------------------------------------
  233.  
  234. ODFrame* FW_CProxyFrame::GetFrame(Environment* ev) const
  235. {
  236.     if (fEmbeddedFrame == NULL)
  237.     {
  238.         FW_ASSERT(fFrameDraft != NULL);
  239.         
  240.         FW_CProxyFrame* self = (FW_CProxyFrame*)this;
  241.         
  242.         self->fEmbeddedFrame = fFrameDraft->AcquireFrame(ev, fFrameID);
  243.         if (fAttached)
  244.             fEmbeddedFrame->SetInLimbo(ev, FALSE);    // Just in case
  245.             
  246.         FW_ASSERT(fEmbeddedFrame != NULL);
  247.     }
  248.     
  249.     return fEmbeddedFrame;
  250. }
  251.  
  252. //----------------------------------------------------------------------------------------
  253. //    FW_CProxyFrame::IsVisible
  254. //----------------------------------------------------------------------------------------
  255.  
  256. FW_Boolean FW_CProxyFrame::IsVisible(Environment* ev, ODFacet* containingFacet, const FW_CRect& bounds) const
  257. {
  258.     FW_CAcquiredODShape aqClipShape = containingFacet->AcquireClipShape(ev, NULL);
  259.     FW_CRect clipRect = FW_GetShapeBoundingBox(ev, aqClipShape);
  260.     
  261.     FW_CAcquiredODTransform aqInternalTransform = containingFacet->GetFrame(ev)->AcquireInternalTransform(ev, NULL);
  262.     FW_CRect tempRect = bounds.TransformCopy(ev, aqInternalTransform);
  263.     
  264.     if (clipRect.IsIntersecting(tempRect))
  265.         return TRUE;
  266.     
  267.     return FALSE;
  268. }
  269.  
  270. //----------------------------------------------------------------------------------------
  271. //    FW_CProxyFrame::SetPurgeable
  272. //----------------------------------------------------------------------------------------
  273.  
  274. void FW_CProxyFrame::SetPurgeable(Environment* ev, FW_Boolean purgeable)
  275. {
  276.     fPurgeable = purgeable;
  277.     
  278.     if (!fPurgeable)
  279.     {
  280.         FW_Boolean wasInMemory = IsFrameInMemory(ev);
  281.         
  282.         GetFrame(ev);    // to be sure that the frame is in memory
  283.  
  284.         // ----- Create facets for the new frame if it was not in memory-----
  285.         if (!wasInMemory)
  286.         {
  287.             FW_ASSERT(fPart->IsValidDisplayFrame(ev, fContainingFrameID));
  288.             CreateAllFacets(ev);
  289.         }
  290.     }
  291. }
  292.  
  293. //----------------------------------------------------------------------------------------
  294. //    FW_CProxyFrame::PrivClose
  295. //----------------------------------------------------------------------------------------
  296.  
  297. void FW_CProxyFrame::PrivClose(Environment* ev)
  298. {
  299.     if (fEmbeddedFrame != NULL)
  300.         fEmbeddedFrame->Close(ev);        // Will call release    
  301.     fEmbeddedFrame = NULL;
  302. }
  303.  
  304. //----------------------------------------------------------------------------------------
  305. //    FW_CProxyFrame::Release
  306. //----------------------------------------------------------------------------------------
  307.  
  308. void FW_CProxyFrame::Release(Environment* ev)
  309. {
  310.     if (fEmbeddedFrame != NULL)
  311.         fEmbeddedFrame->Release(ev);
  312.     fEmbeddedFrame = NULL;
  313. }
  314.  
  315. //----------------------------------------------------------------------------------------
  316. //    ExternalizeInScope
  317. //----------------------------------------------------------------------------------------
  318.  
  319. static void ExternalizeInScope(Environment* ev, ODPart* thePart, ODFrame* scopeFrame)
  320. {
  321.     ODEmbeddedFramesIterator* ite = thePart->CreateEmbeddedFramesIterator(ev, scopeFrame);
  322.     for (ODFrame* embeddedFrame = ite->First(ev); ite->IsNotComplete(ev); embeddedFrame = ite->Next(ev))
  323.     {
  324.         FW_CAcquiredODFrame aqContainingFrame = embeddedFrame->AcquireContainingFrame(ev);
  325.         if (aqContainingFrame == scopeFrame)
  326.         {
  327.             FW_CAcquiredODPart aqEmbeddedPart = embeddedFrame->AcquirePart(ev);
  328.  
  329.             embeddedFrame->Externalize(ev);
  330.             aqEmbeddedPart->Externalize(ev);
  331.             
  332.             ExternalizeInScope(ev, aqEmbeddedPart, embeddedFrame);
  333.         }
  334.     }
  335.     
  336.     delete ite;
  337. }
  338.  
  339. //----------------------------------------------------------------------------------------
  340. //    FW_CProxyFrame::Purge
  341. //----------------------------------------------------------------------------------------
  342.  
  343. ODSize FW_CProxyFrame::Purge(Environment* ev)
  344. {
  345.     if (!IsFrameInMemory(ev))
  346.         return 0;                // already gone
  347.         
  348.     // [HLX] I am not sure about that. If purge is called in a middle of a drag&drop I
  349.     // may not be the owner of this frame anymore ????
  350.     FW_CAcquiredODFrame aqODContainingFrame = fEmbeddedFrame->AcquireContainingFrame(ev);
  351.     FW_CAcquiredODPart aqODContainingPart = aqODContainingFrame->AcquirePart(ev);
  352.     if (aqODContainingPart != fPart->GetODPart(ev))
  353.         fPurgeable = FALSE;
  354.     
  355.     if (fPurgeable)
  356.     {
  357.         // ----- HLX] OpenDoc Bug????
  358.         fEmbeddedFrame->Externalize(ev);
  359.         FW_CAcquiredODPart aqEmbeddedPart = fEmbeddedFrame->AcquirePart(ev);
  360.         aqEmbeddedPart->Externalize(ev);
  361.         ExternalizeInScope(ev, aqEmbeddedPart, fEmbeddedFrame);
  362.         // ----- [HLX] OpenDoc Bug????
  363.         
  364.         // ----- Remove its facets
  365.         FW_ASSERT(fPart->IsValidDisplayFrame(ev, fContainingFrameID));
  366.         this->RemoveAllFacets(ev);
  367.     
  368.         // ----- Now I can release the frame
  369.         Release(ev);
  370.     }
  371.     
  372.     return 0;  // [HLX] need to be able to get the size of what I am releasing
  373. }
  374.  
  375. //----------------------------------------------------------------------------------------
  376. //    FW_CProxyFrame::InternalizeProxyFrame
  377. //----------------------------------------------------------------------------------------
  378. //    returns true if valid 
  379.  
  380. FW_Boolean FW_CProxyFrame::InternalizeProxyFrame(Environment* ev, ODStorageUnitView* suView, FW_CCloneInfo* cloneInfo)
  381. {
  382.     ODStorageUnitRef aSURef;    
  383.     FW_CByteArray byteArray;
  384.         
  385.     // ----- Read reference -----
  386.     suView->GetValue(ev, sizeof(ODStorageUnitRef), byteArray);
  387.     byteArray.CopyBuffer(&aSURef, sizeof(ODStorageUnitRef));
  388.     
  389.     if (!suView->IsValidStorageUnitRef(ev, aSURef))
  390.         return FALSE;
  391.     
  392.     ODStorageUnitID fromFrameID = suView->GetIDFromStorageUnitRef(ev, aSURef);
  393.  
  394.     if (cloneInfo != NULL)
  395.     {
  396.         // ----- We are cloning -----
  397.         fFrameID = cloneInfo->Clone(ev, fromFrameID, 0, 0);
  398.         fFrameDraft = cloneInfo->GetToDraft(ev);
  399.         
  400.         fContainingFrameID = cloneInfo->GetScopeFrame(ev)->GetID(ev);
  401.     }
  402.     else
  403.     {
  404.         // ----- Save the frame's draft
  405.         fFrameDraft = suView->GetStorageUnit(ev)->GetDraft(ev);
  406.         
  407.         // ----- Cache the id of the containing frame -----
  408.         FW_CAcquiredODStorageUnit aqFrameSU = fFrameDraft->AcquireStorageUnit(ev, fromFrameID);
  409.         aqFrameSU->Focus(ev, kODPropContainingFrame, kODPosUndefined, kODWeakStorageUnitRef, 0, kODPosUndefined);
  410.         
  411.         aqFrameSU->GetValue(ev, sizeof(ODStorageUnitRef), byteArray);
  412.         byteArray.CopyBuffer(&aSURef, sizeof(ODStorageUnitRef));
  413.  
  414.         if (aqFrameSU->IsValidStorageUnitRef(ev, aSURef))
  415.             fContainingFrameID = aqFrameSU->GetIDFromStorageUnitRef(ev, aSURef);
  416.         else
  417.             fContainingFrameID = kODNULLID;
  418.  
  419.         // ----- Now we can set the frame ID -----
  420.         fFrameID = fromFrameID;
  421.     }
  422.     
  423.     return TRUE;
  424. }
  425.  
  426. //----------------------------------------------------------------------------------------
  427. //    FW_CProxyFrame::ExternalizeProxyFrame
  428. //----------------------------------------------------------------------------------------
  429.  
  430. FW_Boolean FW_CProxyFrame::ExternalizeProxyFrame(Environment* ev, ODStorageUnitView* suView, FW_CCloneInfo* cloneInfo)
  431. {
  432.     FW_ASSERT(fPart->IsValidDisplayFrame(ev, fContainingFrameID));
  433.  
  434.     // We only externalize frame that have a persistent containing Frame
  435.     FW_Boolean externalize = GetContainingFrame(ev)->IsPersistent(ev);
  436.  
  437.     ODStorageUnitID frameID = fFrameID;
  438.  
  439.     if (cloneInfo != NULL)
  440.     {
  441.         if (cloneInfo->GetScopeFrame(ev) != NULL)
  442.             externalize = (cloneInfo->GetScopeFrame(ev)->GetID(ev) == fContainingFrameID);
  443.         
  444.         if (externalize)
  445.             frameID = cloneInfo->Clone(ev, fFrameID, 0, fFrameID);
  446.     }
  447.     
  448.     if (externalize)
  449.     {
  450.         // ----- Write out the embedded frame reference -----
  451.         ODStorageUnitRef aSURef;
  452.         FW_CByteArray byteArray(&aSURef, sizeof(ODStorageUnitRef));
  453.          suView->GetStrongStorageUnitRef(ev, frameID, aSURef);
  454.         suView->SetValue(ev, byteArray);
  455.     }
  456.     
  457.     return externalize;
  458. }
  459.  
  460. //----------------------------------------------------------------------------------------
  461. //    FW_CProxyFrame::SetProxy
  462. //----------------------------------------------------------------------------------------
  463.  
  464. void FW_CProxyFrame::SetProxy(Environment* ev, FW_MProxy* proxy)
  465. {
  466. FW_UNUSED(ev);
  467.     FW_ASSERT(fProxy == NULL || proxy == NULL || fProxy == proxy);
  468.     fProxy = proxy;
  469. }
  470.  
  471. //----------------------------------------------------------------------------------------
  472. //    FW_CProxyFrame::SetContainingFrame
  473. //----------------------------------------------------------------------------------------
  474. // We can't change the containing frame is this proxyframe is not orphaned
  475.  
  476. void FW_CProxyFrame::SetContainingFrame(Environment* ev, FW_CEmbeddingFrame* containingFrame)
  477. {
  478.     FW_ASSERT(IsOrphan(ev));
  479.     fContainingFrameID = containingFrame->GetID(ev);
  480.     
  481.     ODFrame* embeddedFrame = GetFrame(ev);    // Need to bring it into memory
  482.     embeddedFrame->SetContainingFrame(ev, containingFrame->GetODFrame(ev));
  483. }
  484.  
  485. //----------------------------------------------------------------------------------------
  486. //    FW_CProxyFrame::PrivAttach
  487. //----------------------------------------------------------------------------------------
  488.  
  489. void FW_CProxyFrame::PrivAttach(Environment* ev)
  490. {
  491.     FW_CEmbeddingFrame* embeddingFrame = GetContainingFrame(ev);
  492.     if (embeddingFrame != NULL && !fAttached)    
  493.     {
  494.         // [HLX] I have to load the frame. Is this a problem?
  495.         ODFrame* odEmbeddedFrame = GetFrame(ev);
  496.     
  497.         odEmbeddedFrame->SetContainingFrame(ev, embeddingFrame->GetODFrame(ev));
  498.         odEmbeddedFrame->SetInLimbo(ev, FALSE);
  499.         
  500.         // ----- It is now attached -----
  501.         fAttached = TRUE;
  502.     
  503.         // ----- Create the facets -----
  504.         CreateAllFacets(ev);
  505.     }
  506. }
  507.  
  508. //----------------------------------------------------------------------------------------
  509. //    FW_CProxyFrame::PrivDetach
  510. //----------------------------------------------------------------------------------------
  511.  
  512. void FW_CProxyFrame::PrivDetach(Environment* ev)
  513. {
  514.     FW_CEmbeddingFrame* embeddingFrame = GetContainingFrame(ev);
  515.     if (embeddingFrame != NULL && fAttached)
  516.     {
  517.         this->RemoveAllFacets(ev);
  518.     
  519.         // [HLX] I have to load the frame. Is this a problem?
  520.         ODFrame* odEmbeddedFrame = GetFrame(ev);
  521.             
  522.         // ----- Set the containing frame to null -----
  523.         FW_CAcquiredODFrame aqODContainingFrame = odEmbeddedFrame->AcquireContainingFrame(ev);
  524.         if (aqODContainingFrame == NULL || aqODContainingFrame == embeddingFrame->GetODFrame(ev))
  525.         {
  526.             odEmbeddedFrame->SetInLimbo(ev, TRUE);
  527.             odEmbeddedFrame->SetContainingFrame(ev, NULL);
  528.         }
  529.                 
  530.         // ----- It is now detached -----
  531.         fAttached = FALSE;
  532.     }
  533. }
  534.  
  535. //----------------------------------------------------------------------------------------
  536. //    FW_CProxyFrame::RemoveAllFacets
  537. //----------------------------------------------------------------------------------------
  538. //    Remove all the facets of this proxyframe
  539.  
  540. void FW_CProxyFrame::RemoveAllFacets(Environment* ev)
  541. {
  542.     FW_CEmbeddingFrame* embeddingFrame = GetContainingFrame(ev);
  543.     
  544.     if (embeddingFrame && this->IsFrameInMemory(ev))
  545.     {
  546.         FW_CFrameFacetIterator ite(ev, embeddingFrame);
  547.         for (ODFacet* facet = ite.First(ev); ite.IsNotComplete(ev); facet = ite.Next(ev))
  548.             this->RemoveFacets(ev, embeddingFrame, facet);
  549.     }
  550. }
  551.  
  552. //----------------------------------------------------------------------------------------
  553. //    FW_CProxyFrame::RemoveFacets
  554. //----------------------------------------------------------------------------------------
  555. //    Remove all the facet embedded in embeddingFacet
  556.  
  557. void FW_CProxyFrame::RemoveFacets(Environment* ev, FW_CEmbeddingFrame* frame, ODFacet* embeddingFacet)
  558. {
  559.     FW_ASSERT(frame != NULL);
  560.     FW_ASSERT(embeddingFacet != NULL);
  561.     
  562.     if (!this->IsFrameInMemory(ev))    // if not in memory should not have any facets
  563.         return;
  564.     
  565.     ODFrame* embeddedFrame = this->GetFrame(ev);
  566.     
  567.     FW_TOrderedCollection<ODFacet> tempCollect;
  568.  
  569.     // Attention: Do not try to iterate through all the facets of the embedded frame because
  570.     //    if we are in a middle of a drag&drop, the embedded frame may already have been stripped
  571.     //    of all its facets (in the case where the frame is reused, SetContainingFrame is called
  572.     //    which remove all the facets of the frame). But the hierarchy of facets is still there
  573.     FW_CFacetIterator ite(ev, embeddingFacet, kODChildrenOnly, kODFrontToBack);
  574.     ODFacet* facet;
  575.     for (facet = ite.First(ev); ite.IsNotComplete(ev); facet = ite.Next(ev))
  576.     {
  577.         if (facet->GetFrame(ev) == embeddedFrame)
  578.             tempCollect.AddLast(facet);
  579.     }
  580.     
  581.     FW_TOrderedCollectionIterator<ODFacet> ite2(&tempCollect);
  582.     for (facet = ite2.First(); ite2.IsNotComplete(); facet = ite2.Next())
  583.     {
  584.         frame->EmbeddedFacetRemoved(ev, facet);        // Notify Embedding frame
  585.         fProxy->PrivEmbeddedFacetRemoved(ev);        // Notify proxy
  586.         
  587.         embeddingFacet->RemoveFacet(ev, facet);
  588.         delete facet;
  589.     }
  590.     
  591.     // RemoveAll will be called by the destructor of tempCollect 
  592.     // tempCollect.RemoveAll();
  593. }
  594.  
  595.  
  596. //----------------------------------------------------------------------------------------
  597. //    FW_CEmbeddingFrame::CreateAllFacets
  598. //----------------------------------------------------------------------------------------
  599.  
  600. FW_DECLARE_THROW_POINT (FW_CProxyFrame_CreateAllFacets);
  601.  
  602. void FW_CProxyFrame::CreateAllFacets(Environment* ev)                                        
  603. {    
  604.     FW_CEmbeddingFrame* embeddingFrame = GetContainingFrame(ev);
  605.     FW_ASSERT(embeddingFrame);
  606.     
  607.     if (!IsFrameInMemory(ev) || !fProxy->IsShown(ev))
  608.         return;
  609.         
  610.     FW_CFrameFacetIterator ite(ev, embeddingFrame);
  611.     // Exception Handling: as with all loops, if one pass fails we need to undo the 
  612.     // effects of the previous ones.
  613.     FW_TRY 
  614.     {
  615.         for (ODFacet* containingFacet = ite.First(ev); ite.IsNotComplete(ev); containingFacet = ite.Next(ev))
  616.         {
  617.             CreateFacets(ev, embeddingFrame, containingFacet);
  618.             
  619.             // Testing: what happens if one facet is created and then we fail? (as 
  620.             // if we tried and failed to create two facets?)
  621.             FW_CHECK_THROW_POINT (FW_CProxyFrame_CreateAllFacets);
  622.         }
  623.     }
  624.     FW_CATCH_BEGIN
  625.     FW_CATCH_EVERYTHING () 
  626.     {
  627.         RemoveAllFacets(ev);
  628.         FW_THROW_SAME ();
  629.     }
  630.     FW_CATCH_END
  631. }
  632.  
  633. //----------------------------------------------------------------------------------------
  634. //    FW_CProxyFrame::CreateFacets
  635. //----------------------------------------------------------------------------------------
  636.  
  637. FW_DECLARE_THROW_POINT (FW_CProxyFrame_CreateFacets);
  638.  
  639. void FW_CProxyFrame::CreateFacets(Environment* ev, FW_CEmbeddingFrame* frame, ODFacet* embeddingFacet)                                        
  640. {
  641.     FW_ASSERT(embeddingFacet);
  642.     
  643.     if (!IsFrameInMemory(ev) || !fProxy->IsShown(ev))
  644.         return;
  645.     
  646.     ODFrame* embeddedFrame = this->GetFrame(ev);
  647.     
  648.     FW_CAcquiredODShape proposedClipShape = FW_CopyAndRelease(ev, embeddedFrame->AcquireFrameShape(ev, NULL));
  649.  
  650.     frame->CreateEmbeddedFacet(ev,
  651.                                 embeddingFacet,
  652.                                 fProxy,
  653.                                 embeddedFrame,
  654.                                 proposedClipShape);
  655.     
  656.     // ----- I need to go through all the embedded facets because I don't know how many where added -----
  657.     // For example, if we embedded Puzzle part then it would create 9 embedded facets. That's
  658.     // why CreateEmbeddedFacet doesn't return a pointer to the "one" created facet.
  659.     FW_TRY {
  660.         FW_CFacetIterator ite(ev, embeddingFacet, kODChildrenOnly, kODFrontToBack);
  661.         for (ODFacet* embeddedFacet = ite.First(ev); ite.IsNotComplete(ev); embeddedFacet = ite.Next(ev))
  662.         {
  663.             if (embeddedFacet->GetFrame(ev) == embeddedFrame)
  664.             {
  665.                 embeddedFacet->SetSelected(ev, fProxy->GetSelectState(ev));
  666.                 frame->EmbeddedFacetAdded(ev, embeddedFacet);        // Notify containing frame
  667.                 fProxy->PrivEmbeddedFacetAdded(ev);                    // Notify proxy
  668.             }
  669.             
  670.             // Testing: what happens if one facet is created and then we fail? (as 
  671.             // if we tried and failed to create two facets?)
  672.             FW_CHECK_THROW_POINT (FW_CProxyFrame_CreateFacets);
  673.         }
  674.     }
  675.     FW_CATCH_BEGIN 
  676.     FW_CATCH_EVERYTHING () {
  677.         // This actually removes embedded facets of the proxyFrame *in* this embeddingFacet
  678.         RemoveFacets(ev, frame, embeddingFacet);
  679.         FW_THROW_SAME ();
  680.     }
  681.     FW_CATCH_END
  682. }
  683.  
  684. //----------------------------------------------------------------------------------------
  685. //    FW_CProxyFrame::PrivSetFrameGroup
  686. //----------------------------------------------------------------------------------------
  687.  
  688. void FW_CProxyFrame::PrivSetFrameGroup(Environment* ev, ODID frameGroup)
  689. {
  690.     GetFrame(ev)->SetFrameGroup(ev, frameGroup);
  691. }
  692.  
  693. //----------------------------------------------------------------------------------------
  694. //    FW_CProxyFrame::PrivChangeSequenceNumber
  695. //----------------------------------------------------------------------------------------
  696.  
  697. void FW_CProxyFrame::PrivChangeSequenceNumber(Environment* ev, ODID sequenceNumber)
  698. {
  699.     GetFrame(ev)->ChangeSequenceNumber(ev, sequenceNumber);
  700. }
  701.  
  702.  
  703.  
  704.